package com.snopy.netty;

import com.snopy.utils.ByteBufferUtil;

import java.io.*;
import java.nio.ByteBuffer;

import java.nio.channels.FileChannel;

/**
 * @author snopy
 * @version 1.0.0
 * @classname ChannelDemo
 * @description
 * @email 77912204@qq.com
 * @date 2022/05/11 20:48
 */
public class ChannelDemo {
    public static void main(String[] args){

        try(FileChannel channel = new FileInputStream("F:\\workspaceA\\Sonata\\Sonata_test\\src\\main\\resources\\buffer.txt").getChannel()) {
            ByteBuffer buffer = ByteBuffer.allocate(10);
            int read = channel.read(buffer);
            while (read!=-1) {
                buffer.flip();
                while (buffer.hasRemaining()) {
                    System.out.println((char) buffer.get());
                    ByteBufferUtil.debugAll(buffer);

                }
                buffer.clear();
                read = channel.read(buffer);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }



    }

}
